<template>
    <view class="page-wrap">
        <view class="form">
            <u-form :model="form" ref="uForm" label-width="6em">
                <u-form-item borderBottom label="姓名" prop="memberName">
                    <u-input placeholder="请输入姓名" v-model="form.memberName" :disabled="disabled" />
                </u-form-item>
                <u-form-item borderBottom label="联系电话" prop="memberMobile">
                    <u-input placeholder="请输入联系电话" v-model="form.memberMobile" :disabled="disabled" />
                </u-form-item>
                <u-form-item borderBottom label="备注" prop="remark">
                    <u-input placeholder="请输入备注" v-model="form.remark" :disabled="disabled" />
                </u-form-item>
            </u-form>
            <view class="footer" v-if="!disabled">
                <u-button shape="circle" type="primary" @click="handleSave">保　存</u-button>
            </view>

        </view>
        <global-components ref="global-components" :loading="false"></global-components>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                disabled: false,
                form: {
                    id: '',
                    activityId: '',
                    memberName: '',
                    memberMobile: '',
                    remark: '',
                },
            };
        },
        computed: {},
        methods: {
            toRegister(id) {
                this.$toPage({
                    url: '/pages/activity/regist?id=' + id
                });
            },
            handleSave() {
                this.$api.activity.register(this.form).then(res => {
                    uni.showModal({
                        title: '提示',
                        content: '保存成功！',
                        showCancel: false,
                        success: (res) => {
                            this.$toPage({
                                type: 'back'
                            });
                        }
                    });
                });
            },
        },
        watch: {},
        onLoad(option) {
            if (option.id) {
                this.$api.activity.registration({
                    id: option.id
                }).then(res => {
                    Object.entries(res.info).forEach(([key, val]) => {
                        if (this.form[key] !== undefined) {
                            this.form[key] = val;
                        }
                    });
                })
            } else {
                this.form.activityId = option.activityId;
            }
        },
        onShow() {},
        onHide() {},
    };
</script>
<style scoped lang="scss">
    .page-wrap {

        .form {
            padding: 0 32rpx 32rpx;
            background-color: #fff;
        }

        .footer {
            padding-top: 32rpx;
        }
    }
</style>